#!/usr/bin/env bash
# This file is part of the kernelstudio package.
#
# (c) 2014-2025 zlin <admin@kernelstudio.com>
#
# For the full copyright and license information, please view the LICENSE file
# that was distributed with this source code.

set -e

main(){
    cd /app || exit 1

    if [[ "${MIGRATION_ENABLED:-true}" == "true" ]]; then
        echo "Running migrations"
        flask db migrate
        flask db upgrade
    fi

    if [[ "${DEBUG}" == "true" ]]; then
        exec flask run --host="${APP_HOST:-0.0.0.0}" --port="${APP_PORT:-4444}" --debug
    else
        exec python app.py
    fi
}

main